package com.scorpio.api.controller.basic;

import java.util.List;

import com.scorpio.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.scorpio.common.annotation.Log;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.AjaxResult;
import com.scorpio.common.enums.BusinessType;
import com.scorpio.basic.domain.BannerEntity;
import com.scorpio.basic.service.IBannerService;
import com.scorpio.common.utils.poi.ExcelUtil;
import org.springframework.validation.annotation.Validated;
import com.scorpio.common.utils.verification.AddGroup;
import com.scorpio.common.utils.verification.DefaultGroup;
import com.scorpio.common.utils.verification.UpdateGroup;


/**
 * 首页bannerController
 *
 * @author scorpio
 * @date 2021-10-29
 */
@RestController
@RequestMapping("/basic/banner")
public class BannerController extends BaseController {
    @Autowired
    private IBannerService service;

    /**
     * 查询首页banner列表
     */
    @PreAuthorize("@ss.hasPermi('basic:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(BannerEntity banner) {
        startPage();
        List<BannerEntity> list = service.selectList(banner);
        return getDataTable(list);
    }

    /**
     * 获取首页banner详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(service.selectById(id));
    }

    /**
     * 新增首页banner
     */
    @PreAuthorize("@ss.hasPermi('basic:banner:add')")
    @Log(title = "首页banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(value = {AddGroup.class, DefaultGroup.class}) BannerEntity entity) {
        return toAjax(service.save(entity));
    }

    /**
     * 修改首页banner
     */
    @PreAuthorize("@ss.hasPermi('basic:banner:edit')")
    @Log(title = "首页banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(value = {UpdateGroup.class, DefaultGroup.class}) BannerEntity entity) {
        return toAjax(service.update(entity));
    }

    /**
     * 删除首页banner
     */
    @PreAuthorize("@ss.hasPermi('basic:banner:remove')")
    @Log(title = "首页banner", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
